async function Translation (content, language) {
  const axios = require('axios')

  const direction = language // 翻译方向，英语翻译为中文
  const source = content // 要翻译的文本

  if (source === '') {
    return ''
  } else {
    const data = {
      source: [source],
      trans_type: direction,
      replaced: true,
      media: 'text',
      request_id: 'demo'
    }

    const headers = {
      'Content-Type': 'application/json',
      'X-Authorization': 'token 6sz4xaxvs3irn63ghvwc'
    }

    const url = 'http://api.interpreter.caiyunai.com/v1/translator'

    try {
      const response = await axios.post(url, data, { headers })
      const target = response.data.target[0]
      return target
    } catch (error) {
      console.error(error)
      return error
    }
  }
}

module.exports = {
  Translation
}
